/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * LearningSystemParameterViewer.java
 *
 * Created on Feb 22, 2011, 5:17:49 PM
 */

package wekinator;

import wekinator.LearningAlgorithms.LearningAlgorithm;
import wekinator.LearningAlgorithms.LearningAlgorithm.TrainingState;

/**
 *
 * @author fiebrink
 */
public class LearningSystemParameterViewer extends javax.swing.JPanel {

    /** Creates new form LearningSystemParameterViewer */
    public LearningSystemParameterViewer() {
        initComponents();
    }

    public LearningSystemParameterViewer(LearningSystem s, int paramNum) {
        initComponents();
        labelName.setText("Parameter " + (paramNum + 1));


        LearningAlgorithm a = s.getLearners(paramNum);
        if (a == null) {
            labelAlgorithmState.setText("No algorithm set");
            labelAlgorithmName.setText("");
        } else {
            TrainingState ts = a.getTrainingState();
            if (ts == TrainingState.NOT_TRAINED)
                labelAlgorithmState.setText("Algorithm not trained");
            else if (ts == TrainingState.TRAINED)
                labelAlgorithmState.setText("Algorithm trained");
            else if (ts == TrainingState.TRAINING)
                labelAlgorithmState.setText("Algorithm saved during training");
            else
                labelAlgorithmState.setText("Algorithm in unknown state");

            labelAlgorithmName.setText(a.getName());
        }

        SimpleDataset d = s.getDataset();
        if (d != null) {
            labelNumFeatures.setText(d.getNumFeaturesForParam(paramNum) + " features selected:");
            if (d.isParameterDiscrete(paramNum)) {
                String ss = "Discrete, maxValue=" + d.maxLegalDiscreteParamValue(paramNum) + ", "
                        + (s.isParamUsingDistribution(paramNum) ? " using distribution" : " not using distribution");
                labelType.setText(ss);


            } else {
                labelType.setText("Real-valued");

            }

            String featString = "";
            for (int i = 0; i < d.getNumFeatures(); i++) {
                if (d.isFeatureActiveForParameter(i, paramNum)) {
                    featString += d.getFeatureName(i) + "\n";
                
                }
            
            }
            textFeatureNames.setText(featString);


        } else {
            labelNumFeatures.setText("No dataset created, so no info on selected features");
        }

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        labelName = new javax.swing.JLabel();
        labelType = new javax.swing.JLabel();
        labelAlgorithmState = new javax.swing.JLabel();
        labelAlgorithmName = new javax.swing.JLabel();
        labelNumFeatures = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        textFeatureNames = new javax.swing.JTextPane();

        labelName.setText("Parameter N");

        labelType.setText("Discrete, maximum value=100, not using distribution");

        labelAlgorithmState.setText("Algorithm trained");

        labelAlgorithmName.setText("Support vector machine");

        labelNumFeatures.setText("12 features selected:");

        textFeatureNames.setEditable(false);
        jScrollPane1.setViewportView(textFeatureNames);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 382, Short.MAX_VALUE)
                .addContainerGap())
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(labelName)
                    .add(layout.createSequentialGroup()
                        .add(24, 24, 24)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(labelAlgorithmState)
                            .add(labelAlgorithmName)
                            .add(labelNumFeatures)
                            .add(labelType, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 358, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(labelName)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(labelType)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(labelAlgorithmState)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(labelAlgorithmName)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(labelNumFeatures)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 103, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labelAlgorithmName;
    private javax.swing.JLabel labelAlgorithmState;
    private javax.swing.JLabel labelName;
    private javax.swing.JLabel labelNumFeatures;
    private javax.swing.JLabel labelType;
    private javax.swing.JTextPane textFeatureNames;
    // End of variables declaration//GEN-END:variables

}
